package com.qianfeng.dbsm.impl;

import com.qianfeng.dbsm.entity.TbProductCosmetics;
import com.qianfeng.dbsm.dao.TbProductCosmeticsDao;
import com.qianfeng.dbsm.service.TbProductCosmeticsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 化妆品商品表(TbProductCosmetics)表服务实现类
 *
 * @author makejava
 * @since 2022-11-17 21:01:44
 */
@Service("tbProductCosmeticsService")
public class TbProductCosmeticsServiceImpl implements TbProductCosmeticsService {
    @Resource
    private TbProductCosmeticsDao tbProductCosmeticsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param productCosmeticsId 主键
     * @return 实例对象
     */
    @Override
    public TbProductCosmetics queryById(Integer productCosmeticsId) {
        return this.tbProductCosmeticsDao.queryById(productCosmeticsId);
    }

    /**
     * 分页查询
     *
     * @param tbProductCosmetics 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbProductCosmetics> queryByPage(TbProductCosmetics tbProductCosmetics, PageRequest pageRequest) {
        long total = this.tbProductCosmeticsDao.count(tbProductCosmetics);
        //return new PageImpl<>(this.tbProductCosmeticsDao.queryAllByLimit(tbProductCosmetics, pageRequest), pageRequest, total);
        return null;
    }

    /**
     * 新增数据
     *
     * @param tbProductCosmetics 实例对象
     * @return 实例对象
     */
    @Override
    public TbProductCosmetics insert(TbProductCosmetics tbProductCosmetics) {
        this.tbProductCosmeticsDao.insert(tbProductCosmetics);
        return tbProductCosmetics;
    }

    /**
     * 修改数据
     *
     * @param tbProductCosmetics 实例对象
     * @return 实例对象
     */
    @Override
    public TbProductCosmetics update(TbProductCosmetics tbProductCosmetics) {
        this.tbProductCosmeticsDao.update(tbProductCosmetics);
        return this.queryById(tbProductCosmetics.getProductCosmeticsId());
    }

    /**
     * 通过主键删除数据
     *
     * @param productCosmeticsId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer productCosmeticsId) {
        return this.tbProductCosmeticsDao.deleteById(productCosmeticsId) > 0;
    }
}
